#ifndef  FRAME_CHANNEL_H
#define  FRAME_CHANNEL_H


#include <string>

#include  "Interface.h" //for IChannel

namespace frame {

class ChannelImpl;
class IChannelHandlerAdapter;
class Channel : public IChannel, public std::enable_shared_from_this<Channel> {
public:
    Channel(IChannelHandlerAdapter::Ptr handlerAdapter);
    ~Channel() override;

    bool isConnected() const override{
        return connected;
    }
    void setConnected(bool connected) override;

    int write(const char * buf, int size) override ;
    int write(const std::string & str) override ;
    int disconnect() override;


    const std::string & getRemoteIp() override ;
    const int getRemotePort() override;
    const std::string & getLocalIp() override ;
    const int getLocalPort() override;

    IChannelHandlerAdapter::Ptr getHandlerAdapter() const override{
        return handlerAdapter;
    }


    uint64_t getId() const override {
        return id;
    }
    void setId(const uint64_t id) override {
        this->id = id;
    }

    bool isOpen() override { 
        return opened;
    }
    int open() override;
    void close() override;

public:
    void setImpl(std::shared_ptr<ChannelImpl> channelImpl) override{
        impl = channelImpl;
    }
private:
    std::shared_ptr<ChannelImpl> impl;
    IChannelHandlerAdapter::Ptr handlerAdapter;

    uint64_t id;
    bool opened;
    bool connected;

    std::string remoteIp;
    int remotePort;
    std::string localIp;
    int localPort;

};

} //end of namespace frame
#endif   /* FRAME_CHANNEL_H */
